var http = require("http");
var url=require("url")

function start(route,handle) {
    function onRequest(request, response) {
        var pathname=url.parse(request.url).pathname
        console.log("Request received for " + pathname);
        route(handle, pathname, response, request);
        // var postData = "";
        // request.setEncoding("utf8");
        // request.addListener("data", function (postDataChunk) {
        //     postData+=postDataChunk;
        //     console.log("Receive post data chunk " + postDataChunk);
        //
        // });
        // request.addListener("end",function () {
        //     route(handle,pathname,response,postData)
        // })
        // response.writeHead(200, {"Content-Type": "text/plain"});
        // var content=route(handle,pathname)

        // console.log(content)
        // response.write(content);
        // response.end();
    }

    http.createServer(onRequest).listen(8888);
    console.log("Server is running...")
}



exports.start=start